package org.example.mydeom.security;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.example.mydeom.util.ResultUtil;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Component
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
            throws IOException {
        ResultUtil.Respond( request.getAttribute("error")==null ? "注销成功":request.getAttribute("error").toString()
                , "", 1, response);
//        Result<Object> result = new Result<>();
//        result.setCode(1);
//        result.setMsg("注销成功");
//        String jsonString = JSON.toJSONString(result);
//        response.setContentType("application/json;charset=UTF-8");
//        response.getWriter().write(jsonString);
    }
}
